﻿using System;
using System.Windows.Forms;
using System.Text;

namespace Zove.Desktop
{
    public partial class AddProgramDialog : Form
    {
        public AddProgramDialog()
        {
            InitializeComponent();
        }

        public AddProgramDialog(string selectedPath)
            : this()
        {
            this.tbDirectory.Enabled = false;
            this.SelectedPath = selectedPath;
        }

        public AddProgramDialog(DialogType type)
            : this()
        {
            switch (type)
            {
                case DialogType.Program:
                    break;
                case DialogType.Text:
                    break;
                case DialogType.Xml:
                    break;
                default:
                    break;
            }
        }

        public AddProgramDialog(string folder, DialogType type)
            : this(folder)
        {

        }

        public string FileName
        {
            get
            {
                return this.tbName.Text;
            }
        }

        public string SelectedPath
        {
            get
            {
                return this.tbDirectory.Text;
            }
            set
            {
                this.tbDirectory.Text = value;
            }
        }

        public string ProgramSource
        {
            get
            {
                StringBuilder buff = new StringBuilder();

                if (this.cblImported.Items.Count > 0)
                {
                    foreach (object item in this.cblImported.Items)
                    {
                        buff.Append("import(\"").Append(item).Append("\"");
                    }
                }

                return buff.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog d = new FolderBrowserDialog();

            if (d.ShowDialog() == DialogResult.OK)
            {
                this.tbDirectory.Text = d.SelectedPath;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnAddImported_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Multiselect = true;
            if (d.ShowDialog() == DialogResult.OK)
            {
                foreach (string n in d.FileNames)
                {
                    this.cblImported.Items.Add(n);
                }
            }
        }

        private void btnRemoveImported_Click(object sender, EventArgs e)
        {
            while (this.cblImported.SelectedItems.Count > 0)
            {
                this.cblImported.Items.Remove(
                    this.cblImported.SelectedItems[0]);
            }
        }
    }
}
